package com.sanyang.pda.presenter;


import com.sanyang.pda.bean.PickingDetailBean;
import com.sanyang.pda.bean.PickingStatisticsBean;
import com.sanyang.pda.contract.PickingStatisticsContract;
import com.sanyang.pda.net.NetUtils;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;
import com.wangshen.base.ui.mvp.base.refresh.BaseRecyclerRefreshPresenter;
import com.wangshen.base.ui.mvp.base.refresh.RequestCallback;

import java.util.List;

import io.reactivex.functions.Consumer;

public class PickingStatisticsPresenter extends BaseRecyclerRefreshPresenter<PickingStatisticsContract.View, PickingStatisticsBean> implements PickingStatisticsContract.Presenter {
    private String en;

    public PickingStatisticsPresenter(String en) {
        this.en = en;
    }

    @Override
    public void onRefresh(RequestCallback<PickingStatisticsBean> callback) {
        pickingStatistics(getCurrentPage(),callback);
    }

    @Override
    public void onLoadMore(RequestCallback<PickingStatisticsBean> callback) {
        pickingStatistics(getCurrentPage(),callback);
    }

    @Override
    public void pickingStatistics(int pageNum, RequestCallback<PickingStatisticsBean> callback) {
        NetUtils.geApi().pickingStatistics(pageNum,10,en)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<PickingStatisticsBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<PickingStatisticsBean>> listBaseRowsAppEntity) throws Exception {
                        callback.onSuccess(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.onFail(throwable.getMessage());
                    }
                });
    }
}
